

const allModel = {
//或将考虑 使用曲面数据传过来后，与x,y匹配拿出z 生成模型
    //圆台
    circleBarModel(oldParams,name) {
        //数组第一个为上半径，第二个为下半径，第三个为长(x),第四个位宽(y)，第五个高,六x左右，七y前后，八z上下
        var params = JSON.parse(JSON.stringify(oldParams));
        var max = params[0]>params[1]?params[0]:params[1];
        var series = {
            name:name+1+"号模型",
            type: 'surface',
            wireframe :{
                show:false
            },
            parametric: true,
            grid3DIndex:name,
            parametricEquation: {
                u: {
                    min: -Math.PI,
                    max: Math.PI,
                    step: Math.PI / 20
                },
                v: {
                    min: 0,
                    max: params[4],
                    step: params[4]
                },
                x: function (u, v) {
                  // console.log(",,,,",((v/params[4]*(params[0]-params[1]) + params[1])*Math.sin(u))/max*(params[2]/2) + params[2]/2 + params[5])
                    return  ((v/params[4]*(params[0]-params[1]) + params[1])*Math.sin(u))/max*(params[2]/2) + params[2]/2 + params[5];
                },
                y: function (u, v) {
                    return  (v/params[4]*(params[0]-params[1]) + params[1])*Math.cos(u)/max*(params[3]/2)+ params[3]/2 + params[6];
                },
                z: function (u, v) {
                    return v+params[7];
                }
            },
            silent: true,
          };
          
          // var labelMax = params[2]>params[3]?params[2]:params[3];
          // // var min = params[5]<params[6]?params[5]:params[6];
          // // var max = labelMax+maxMin[0];
          // var maxMin = [];

          //   maxMin[0] = params[5]<params[6]?params[5]:params[6];
          //   maxMin[1] = labelMax+maxMin[0];
          //   maxMin[2] = maxMin[0];
          //   maxMin[3] = maxMin[1];

          var labelMax = params[2]>params[3]?params[2]:params[3];
          var min = params[5]<params[6]?params[5]:params[6];
          var max2 = labelMax+min;
          var insia = max2 - min;
          var maxMin = [];

          maxMin[0] = -(insia - params[2])/2 + params[5];
          maxMin[1] = (insia - params[2])/2 + params[2] + params[5];
          maxMin[2] = -(insia - params[3])/2 + params[6];
          maxMin[3] = (insia - params[3])/2 + params[3] + params[6];
          // console.log("???????",params)
          // console.log("???????",maxMin)
          // console.log("???????",[params[5],params[5]+params[2],params[6],params[6]+params[3]])
        return {series:series,maxMin:maxMin,realMaxMin:[params[5],params[5]+params[2],params[6],params[6]+params[3]]
          ,minZ:params[7],maxZ:params[7]+params[4]
        }
    },

    //拱形(横向)
    archHorModel(oldParams,name){
        //第一为长(x),二宽(y)，三高,四x左右，五y前后，六z上下
        var params = JSON.parse(JSON.stringify(oldParams));
        var series = {
            name:name+1+"号模型",
            type: 'surface',
            wireframe :{
                show:false
            },
            parametric: true,
            grid3DIndex:name,
            parametricEquation: {
              u: {
                min: 0,
                max: Math.PI,
                step: Math.PI / 30
              },
              v: {
                min: 0,
                max: params[1],
                step: params[1]
              },
              x: function (u, v) {
                return  Math.cos(u)*params[0]/2 + params[0]/2 + params[3];
              },
              y: function (u, v) {
                return  v + params[4];
              },
              z: function (u, v) {
                return Math.sin(u)*params[2] + params[5];
              }
            },
            silent: true,
          };
          
          // var labelMax = params[0]>params[1]?params[0]:params[1];
          // var maxMin = [];
          // if(params[0]>params[1]){
          //   maxMin[0] = params[3];
          //   maxMin[1] = labelMax+params[3];
          //   maxMin[2] = params[4];
          //   maxMin[3] = params[1]+params[4];
          // }else{
          //   maxMin[0] = params[3];
          //   maxMin[1] = params[0]+params[3];
          //   maxMin[2] = params[4];
          //   maxMin[3] = labelMax+params[4];
          // }
          var labelMax = params[0]>params[1]?params[0]:params[1];
          var min = params[3]<params[4]?params[3]:params[4];
          var max = labelMax+min;
          var insia = max - min;
          var maxMin = [];

          maxMin[0] = -(insia - params[0])/2 + params[3];
          maxMin[1] = (insia - params[0])/2 + params[0] + params[3];
          maxMin[2] = -(insia - params[1])/2 + params[4];
          maxMin[3] = (insia - params[1])/2 + params[1] + params[4];
    
        return {series:series,maxMin:maxMin,realMaxMin:[params[3],params[3]+params[0],params[4],params[4]+params[1]]
          ,minZ:params[5],maxZ:params[5]+params[2]
        }
    },

    //拱形(纵向)
    archLonModel(oldParams,name){
        //第一为长(x),二宽(y)，三高,四x左右，五y前后，六z上下
        var params = JSON.parse(JSON.stringify(oldParams));
        var series = {
            name:name+1+"号模型",
            type: 'surface',
            wireframe :{
                show:false
            },
            parametric: true,
            grid3DIndex:name,
            parametricEquation: {
              u: {
                min: 0,
                max: Math.PI,
                step: Math.PI / 30
              },
              v: {
                min: 0,
                max: params[0],
                step: params[0]
              },
              x: function (u, v) {
                return  v + params[3];
              },
              y: function (u, v) {
                return  Math.cos(u)*params[1]/2 + params[1]/2 + params[4];
              },
              z: function (u, v) {
                return Math.sin(u)*params[2] + params[5];
              }
            },
            silent: true,
          };
          
          // var labelMax = params[0]>params[1]?params[0]:params[1];
          // var maxMin = [];
          // if(params[0]>params[1]){
          //   maxMin[0] = params[3];
          //   maxMin[1] = labelMax+params[3];
          //   maxMin[2] = params[4];
          //   maxMin[3] = params[1]+params[4];
          // }else{
          //   maxMin[0] = params[3];
          //   maxMin[1] = params[0]+params[3];
          //   maxMin[2] = params[4];
          //   maxMin[3] = labelMax+params[4];
          // }
          var labelMax = params[0]>params[1]?params[0]:params[1];
          var min = params[3]<params[4]?params[3]:params[4];
          var max = labelMax+min;
          var insia = max - min;
          var maxMin = [];

          maxMin[0] = -(insia - params[0])/2 + params[3];
          maxMin[1] = (insia - params[0])/2 + params[0] + params[3];
          maxMin[2] = -(insia - params[1])/2 + params[4];
          maxMin[3] = (insia - params[1])/2 + params[1] + params[4];
    
        return {series:series,maxMin:maxMin,realMaxMin:[params[3],params[3]+params[0],params[4],params[4]+params[1]]
          ,minZ:params[5],maxZ:params[5]+params[2]
        }
    },

    //平面
    planeModel(oldParams,name){
      //第一为后长(x),二前长(x)，三左宽(y),4右宽(y)，5后高(z),6前高(z),7左高(z),8右高(z)，9x左右，10y前后，11z上下
      var params = JSON.parse(JSON.stringify(oldParams));
      var maxX = params[0]>params[1]?params[0]:params[1];
      var maxY = params[2]>params[3]?params[2]:params[3];
      var series = {
        name:name+1+"号模型",
        type: 'surface',
        parametric: true,
        // shading: 'albedo',
        grid3DIndex:name,
        parametricEquation: {
          u: {
            min: 0,
            max: maxX,
            step: Math.abs(maxX)
          },
          v: {
            min: 0,
            max: maxY,
            step:Math.abs(maxY)
          },
          x: function (u, v) {
            var diff = (Math.abs(params[0]-params[1])/2);
            if(params[0]<params[1]){
              if(v==0){
                u = u==0?u+diff:u-diff;
              }
            }else if(params[0]>params[1]){
              if(v==maxY){
                 u = u==0?u+diff:u-diff;
              }
            }
            return u+params[8];
          },
          y: function (u, v) {
            var diff = (Math.abs(params[2]-params[3])/2);
            if(params[2]<params[3]){
              if(u==0){
                v = v==0?v+diff:v-diff;
              }
            }else if(params[2]>params[3]){
              if(u==maxX){
                v = v==0?v+diff:v-diff;
              }
            }
            return v+params[9];
          },
          //v纵，u横
          z: function (u, v) {
            return (u==0?((u+1)*params[6]):(u/maxX)*params[7])+(v==0?((v+1)*params[4]):(v/maxY)*params[5])+params[10];
            // return v==0?(v+params[4]):(v/maxv)*params[5];
          },
        },
        silent: true,
      }

      var labelMax = undefined;
      var flag = false;
      for(var i = 0;i < 4;i++) {
        if(labelMax == undefined || labelMax <= params[i]){
          labelMax = params[i]
          if(i==0||i==1){
            flag = true;
          }else{
            flag = false;
          }
        }
      }
      var maxMin = [];

      // maxMin[0] = -(insia - params[0])/2 + params[3];
      // maxMin[1] = (insia - params[0])/2 + params[0] + params[3];
      // maxMin[2] = -(insia - params[1])/2 + params[4];
      // maxMin[3] = (insia - params[1])/2 + params[1] + params[4];
//第一为后长(x),二前长(x)，三左宽(y),4右宽(y)，5后高(z),6前高(z),7SSSSSs左高(z),8右高(z)，9x左右，10y前后，11z上下

      var maxX = Math.max(params[0],params[1]);
      var maxY = Math.max(params[2],params[3]);
      var labelMax = Math.max(maxX,maxY);
      // var min = params[3]<params[4]?params[3]:params[4]; 
      var insia = labelMax;
      
      maxMin[0] = -(insia - maxX)/2 + params[8];
      maxMin[1] = (insia - maxX)/2 +maxX + params[8];
      maxMin[2] = -(insia - maxY)/2 + params[9];
      maxMin[3] = (insia - maxY)/2 +maxY + params[9];

      // if(flag){
      //   maxMin[0] = params[8];
      //   maxMin[1] = labelMax+params[8];
      //   maxMin[2] = params[9];
      //   maxMin[3] = maxY+params[9];
      // }else{
      //   maxMin[0] = params[8];
      //   maxMin[1] = maxX+params[8];
      //   maxMin[2] = params[9];
      //   maxMin[3] = labelMax+params[9];
      // }
      // var heightArr = [params[4],params[5],params[6],params[7]]
      return {series:series,maxMin:maxMin,realMaxMin:[params[8],params[8]+maxX,params[9],params[9]+maxY]
        ,minZ:params[10],maxZ:params[10]+Math.max(params[4],params[5],params[6],params[7])
      }

    },
    //竖平面(横向)
    planeHorModel(oldParams,name){
      //第一为上长(x),2下长(x)，3左高(z),4右高(z)，5上宽(y),6下宽(y),7左宽(y),8右宽(y)，9x左右，10y前后，11z上下
      var params = JSON.parse(JSON.stringify(oldParams));
      var maxY = params[0]>params[1]?params[0]:params[1];
      var maxZ = params[2]>params[3]?params[2]:params[3];
      var series = {
        name:name+1+"号模型",
        type: 'surface',
        parametric: true,
        // shading: 'albedo',
        grid3DIndex:name,
        parametricEquation: {
          u: {
            min: 0,
            max: maxY,
            step: Math.abs(maxY)
          },
          v: {
            min: 0,
            max: maxZ,
            step:Math.abs(maxZ)
          },
          x: function (u, v) {
            var diff = (Math.abs(params[0]-params[1])/2);
            if(params[0]<params[1]){
              if(v==maxZ){
                u = u==0?u+diff:u-diff;
              }
            }else if(params[0]>params[1]){
              if(v==0){
                 u = u==0?u+diff:u-diff;
              }
            }
            return u+params[8];
          },
          y: function (u, v) {
            return (u==0?((u+1)*params[6]):(u/maxY)*params[7])+(v==0?((v+1)*params[5]):(v/maxZ)*params[4])+params[9];
          },
          //v纵，u横
          z: function (u, v) {
            var diff = (Math.abs(params[2]-params[3])/2);
            if(params[2]<params[3]){
              if(u==0){
                v = v==0?v+diff:v-diff;
              }
            }else if(params[2]>params[3]){
              if(u==maxY){
                v = v==0?v+diff:v-diff;
              }
            }
            return v+params[10];
          },
        },
        silent: true,
      }

      var labelMax1 = params[4]>params[5]?params[4]:params[5];
      var labelMax2 = params[6]>params[7]?params[6]:params[7];
      var labelMin1 = params[4]<params[5]?params[4]:params[5];
      var labelMin2 = params[6]<params[7]?params[6]:params[7];
      var flag = false;

      var maxMin = [];
//第一为上长(x),2下长(x)，3左高(z),4右高(z)，5上宽(y),6下宽(y),7左宽(y),8右宽(y)，9x左右，10y前后，11z上下
      var maxX2 = Math.max(params[0],params[1]);
      var maxY2 = Math.abs(params[4]-params[5])+Math.abs(params[6]-params[7]);
      var labelMax = Math.max(maxX2,maxY2);
      // var min = params[3]<params[4]?params[3]:params[4]; 
      var insia = labelMax;
      



      var rightMove = 0;
      if(labelMin1>0||labelMin2>0)rightMove = labelMin1+labelMin2;
      maxMin[0] = -(insia - maxX2)/2 + params[8];
      maxMin[1] = (insia - maxX2)/2 +maxX2 + params[8];
      maxMin[2] = -(insia - maxY2)/2 + params[9]+rightMove;
      maxMin[3] = (insia - maxY2)/2 +maxY2 + params[9]+rightMove;
      return {series:series,maxMin:maxMin,realMaxMin:[params[8],params[8]+params[0]>params[1]?params[0]:params[1],rightMove+params[9],labelMax1+labelMax2+params[9]]
        ,minZ:params[10],maxZ:params[10]+Math.max(params[2],params[3])
      }

    },
    //竖平面(纵向)
    planeLonModel(oldParams,name){
      //第一为上宽(y),2下宽(y)，3后高(z),4前高(z)，5上宽(x),6下宽(x),7左宽(x),8右宽(x)，9x左右，10y前后，11z上下
      var params = JSON.parse(JSON.stringify(oldParams));
      var maxX = params[0]>params[1]?params[0]:params[1];
      var maxZ = params[2]>params[3]?params[2]:params[3];
      var series = {
        name:name+1+"号模型",
        type: 'surface',
        parametric: true,
        // shading: 'albedo',
        grid3DIndex:name,
        parametricEquation: {
          u: {
            min: 0,
            max: maxX,
            step: Math.abs(maxX)
          },
          v: {
            min: 0,
            max: maxZ,
            step:Math.abs(maxZ)
          },
          x: function (u, v) {
            return (u==0?((u+1)*params[6]):(u/maxX)*params[7])+(v==0?((v+1)*params[5]):(v/maxZ)*params[4])+params[8];
          },
          y: function (u, v) {
            var diff = (Math.abs(params[0]-params[1])/2);
            if(params[0]<params[1]){
              if(v==maxZ){
                u = u==0?u+diff:u-diff;
              }
            }else if(params[0]>params[1]){
              if(v==0){
                 u = u==0?u+diff:u-diff;
              }
            }
            return u+params[9];
          },
          //v纵，u横
          z: function (u, v) {
            var diff = (Math.abs(params[2]-params[3])/2);
            if(params[2]<params[3]){
              if(u==0){
                v = v==0?v+diff:v-diff;
              }
            }else if(params[2]>params[3]){
              if(u==maxX){
                v = v==0?v+diff:v-diff;
              }
            }
            return v+params[10];
          },
        },
        silent: true,
      }

      var labelMax1 = params[4]>params[5]?params[4]:params[5];
      var labelMax2 = params[6]>params[7]?params[6]:params[7];
      var labelMin1 = params[4]<params[5]?params[4]:params[5];
      var labelMin2 = params[6]<params[7]?params[6]:params[7];
      var flag = false;

      var maxMin = [];

      var maxX2 = Math.abs(params[4]-params[5])+Math.abs(params[6]-params[7]);
      var maxY2 = Math.max(params[0],params[1]);
      var labelMax = Math.max(maxX2,maxY2);
      // var min = params[3]<params[4]?params[3]:params[4]; 
      var insia = labelMax;
      
      var rightMove = 0;
      if(labelMin1>0||labelMin2>0)rightMove = labelMin1+labelMin2
      maxMin[0] = -(insia - maxX2)/2 + params[8]+rightMove;
      maxMin[1] = (insia - maxX2)/2 +maxX2 + params[8]+rightMove;
      maxMin[2] = -(insia - maxY2)/2 + params[9];
      maxMin[3] = (insia - maxY2)/2 +maxY2 + params[9];
      return {series:series,maxMin:maxMin,realMaxMin:[rightMove+params[8],labelMax1+labelMax2+params[8],params[9],params[9]+params[0]>params[1]?params[0]:params[1]]
        ,minZ:params[10],maxZ:params[10]+Math.max(params[2],params[3])
      }

    }

}



export default allModel;